package com.item.springbootswagge.controller;

import com.sun.org.apache.regexp.internal.RE;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Api("测试使用相关的api")
@RestController
public class indexController {
    @Autowired
    private Hello hello;



    /**

     *@描述

     *@参数  []

     *@返回值  java.util.List<java.util.HashMap<java.lang.String,java.lang.Object>>

     *@创建人  wangdong

     *@创建时间  19-4-13/下午1:00

     *@修改人和其它信息

     */
    @ApiOperation(value="获取用户列表", notes="获取用户列表")
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public List<HashMap<String,Object>> list(){
        return null;
    }
    /**

     *@描述

     *@参数  [id]

     *@返回值  java.util.HashMap<java.lang.String,java.lang.Object>

     *@创建人  wangdong

     *@创建时间  19-4-13/下午1:11

     *@修改人和其它信息

     */
    @ApiOperation(value = "查询用户信息",notes = "根据id查询信息")
    @ApiImplicitParam(name = "id",value = "用户id" ,required = true,dataType = "Integer",paramType = "path")
    @RequestMapping(value = "findById/{id}",method = RequestMethod.GET)
    public HashMap<String,Object> findById(@PathVariable(value = "id")Integer id){
        System.out.println("前端传过来的id"+id);

      return null;
    }
    /**

     *@描述

     *@参数  [name]

     *@返回值  java.lang.String

     *@创建人  wangdong

     *@创建时间  19-4-13/下午2:52

     *@修改人和其它信息

     */
    @ApiOperation(value = "线程池测试" , notes = "传入字符串，查看看返回结果")
    @ApiImplicitParam(name = "name",value = "名称",required = true,dataType = "String",paramType = "String")
    @RequestMapping(value = "hello/{name}",method = RequestMethod.GET)
    public String hello(@PathVariable(value = "name")String name) throws  Exception{
        hello.sayHello(name);

        System.out.println("前端传过来的数据:"+name);
        return name;
    }


    @ApiOperation(value = "带有返回值线程",notes = "批量带有返回值的线程，num代表个数")
    @ApiImplicitParam(name = "num",value = "线程个数",required = true,dataType = "Integer",paramType ="String")
    @RequestMapping(value = "ThreadPool/{num}",method = RequestMethod.GET)
    public String ThreadPool(@PathVariable("num")Integer num)throws Exception{

      long startTime =  new Date().getTime();

        for(int i=0;i<num;i++){
            hello.asyncReturnFuture(String.valueOf(i));
        }
      long endTime = new Date().getTime();

        return "耗时："+(endTime-startTime);
    }


}
